home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / partial_cor.pro < prev    next >
Text File  |  1997-07-08  |  1KB  |  58 lines

  1. ; $Id: partial_cor.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1991-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6.  
  7.  function  partial_cor,X,Y,C
  8. ;+
  9. ; NAME: 
  10. ;     PARTIAL_COR
  11. ;
  12. ; PURPOSE:
  13. ;    Compute the partial correlation coefficient between
  14. ;    X and Y after both have been adjusted for the variables in C.
  15. ;
  16. ; CATEGORY:
  17. ;    Statistics.
  18. ;
  19. ; CALLING SEQUENCE: 
  20. ;    Result = PARTIAL_COR(X,Y,C)
  21. ;
  22. ; INPUTS:
  23. ;    X:    column vector of R independent data values.
  24. ;    Y:    column vector of R dependent data values.
  25. ;
  26. ;    C:    two dimensional array with each column containing data
  27. ;        values corresponding to an independent variable.  Each column
  28. ;        has length R.
  29. ;
  30. ; OUTPUT:
  31. ;    The partial correlation coefficient.
  32. ;-
  33.  
  34. SC = size(C)
  35. CNum = SC(1)
  36. W = Replicate(1.0,SC(2))
  37.  
  38. if CNum EQ 1 THEN BEGIN
  39.   P1 = Correlate(X,Y)
  40.   P2 = Correlate(X,C)
  41.   P3 = Correlate(Y,C)
  42.  if ( P2 NE 1 and P3 NE 1) THEN          $
  43.     return, (P1 - P2 * P3)/sqrt((1-P2^2) * (1 - P3^2)) $
  44.   else return,0
  45. ENDIF ELSE BEGIN
  46.   Y1 = transpose(Y)
  47.   Coef = Regress(C,Y1,W,YFit,A0,s,f,r,P1)
  48.    D = [C,X]
  49.   Coef = Regress(D,Y1,W,YFit,A0,s,f,r,P2)
  50.   P1 = 1 - P1^2
  51.   P2 = 1 - P2^2 
  52.   if P1 EQ 0 THEN return,0
  53.  return,sqrt((P1-P2)/P1)
  54.  
  55. ENDELSE
  56.  
  57. end
  58.